﻿using System;
using System.Data;
using System.Collections.Generic;
using KeMei.Model;
namespace KeMei.BLL
{
    /// <summary>
    /// Download
    /// </summary>
    public partial class Download
    {
        private readonly KeMei.DAL.Download dal = new KeMei.DAL.Download();
        public Download()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(KeMei.Model.Download model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(KeMei.Model.Download model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {

            return dal.Delete(ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            return dal.DeleteList(IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public KeMei.Model.Download GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

       
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<KeMei.Model.Download> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<KeMei.Model.Download> DataTableToList(DataTable dt)
        {
            List<KeMei.Model.Download> modelList = new List<KeMei.Model.Download>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                KeMei.Model.Download model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new KeMei.Model.Download();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["TName"] != null && dt.Rows[n]["TName"].ToString() != "")
                    {
                        model.TName = dt.Rows[n]["TName"].ToString();
                    }
                    if (dt.Rows[n]["FileUrl"] != null && dt.Rows[n]["FileUrl"].ToString() != "")
                    {
                        model.FileUrl = dt.Rows[n]["FileUrl"].ToString();
                    }
                    if (dt.Rows[n]["FileDes"] != null && dt.Rows[n]["FileDes"].ToString() != "")
                    {
                        model.FileDes = dt.Rows[n]["FileDes"].ToString();
                    }
                    if (dt.Rows[n]["Recorddate"] != null && dt.Rows[n]["Recorddate"].ToString() != "")
                    {
                        model.Recorddate = DateTime.Parse(dt.Rows[n]["Recorddate"].ToString());
                    }
                    if (dt.Rows[n]["lmID"] != null && dt.Rows[n]["lmID"].ToString() != "")
                    {
                        model.lmID = int.Parse(dt.Rows[n]["lmID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

